const mysql = require('mysql');
const config = require('../../config');

let pool = mysql.createPool(config.mysqlConfig);

pool.on('error', (err) => {
    console.log(err);
})


let asyncExec = (sql, values) => {
    console.log(sql);
    return new Promise((resolve, reject) => {
        pool.getConnection((err, connection) => {
            if (err) {
                reject(err)
            } else {
                connection.query(sql, values, (err, rows) => {
                    if (err) {
    
                        reject(err)
                    } else {
                        resolve(rows)
                    }
                    connection.release();
                })
            }
        })
    })
};

module.exports = {
    asyncExec
}
